package com.bawei.week.visit

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.alibaba.android.arouter.facade.annotation.Route
import com.bawei.lib_base.entity.VisitBeanItem
import com.bawei.lib_base.mvvm.BaseActivity
import com.bawei.week.R
import com.bawei.week.databinding.ActivityParkAddBinding
import com.bawei.week.databinding.ActivityVisitAddBinding
import com.bawei.week.park.ParkViewModel
import com.blankj.utilcode.util.ToastUtils
import dagger.hilt.android.AndroidEntryPoint

@Route(path = "/app/VisitAddActivity")
@AndroidEntryPoint
class VisitAddActivity : BaseActivity<ActivityVisitAddBinding,VisitViewModel>() {
    override fun initView() {
        binding.ivAdd.setOnClickListener {
            val appointmentTime = binding.visitAddAppointmentTime.text.toString() + " " + binding.visitAddStartTime.text.toString()
            val employeeId = binding.visitAddEmployeeId.text.toString().toInt()
            val purpose = binding.visitAddPurpose.text.toString()
            val plateNumber = binding.visitAddPlateNumber.text.toString()
            val phoneNumber = binding.visitAddPhoneNumber.text.toString()
            val visitorName = binding.visitAddVisitorName.text.toString()
            val idNumber = binding.visitAddIdNumber.text.toString()
            val requestParking = binding.visitAddSwitch.isChecked

            val visitBeanItem = VisitBeanItem(
                appointmentTime,
                false,
                arrayListOf(""),
                employeeId,
                1,
                idNumber,
                phoneNumber,
                plateNumber,
                purpose,
                requestParking,
                "待审核",
                visitorName
            )
            vm.getVisitAdd(visitBeanItem)
        }

        binding.visitAddSwitch.setOnCheckedChangeListener { compoundButton, isCheck ->
            binding.visitAddPlateNumber.isEnabled = isCheck
        }

        binding.visitAddIvAppointmentTime.setOnClickListener {
            showDateDialog(binding.visitAddAppointmentTime)
        }

        binding.visitAddIvStartTime.setOnClickListener {
            showTimeDialog(binding.visitAddStartTime)
        }

        binding.visitAddIvEndTime.setOnClickListener {
            showTimeDialog(binding.visitAddEndTime)
        }
    }

    override fun initData() {
        vm.visitAddSuc.observe(this){
            ToastUtils.showShort("添加成功")
            finish()
        }
    }
}